#include <node_api.h>
#include <js_native_api.h>
#include <js_native_api_types.h>
#include <aki/jsbind.h>
#include <cstdlib>
#include <cstring>
#include <multimedia/image_framework/image_source_mdk.h>
#include <multimedia/image_framework/image_pixel_map_mdk.h>
#include <rawfile/raw_file.h>
#include <rawfile/raw_file_manager.h>
#include <hilog/log.h>
#include "rtc_client/client/njs_rtc_client.h"
#include "rtc_client/render/render_scale_type.h"
#include "rtc_client/render/njs_video_render_manager.h"
#include "rtc_client/capturer/njs_camera_capture.h"

static napi_value Init(napi_env env, napi_value exports) {
  exports = ohosrtc::NJSVideoRenderManager::Init(env, exports);
	exports = aki::JSBind::BindSymbols(env, exports);
	return exports;
}

static napi_module registerNativeModule = {
    .nm_version = 1,
    .nm_flags = 0,
    .nm_filename = nullptr,
    .nm_register_func = Init,
    .nm_modname = "entry",
    .nm_priv = ((void*)0),
    .reserved = {0},
};

extern "C" __attribute__((constructor)) void NativeInit(void) {
  napi_module_register(&registerNativeModule);
}


JSBIND_GLOBAL() {
}

namespace ohosrtc {
JSBIND_ENUM(RenderScaleType) {
  JSBIND_ENUM_VALUE(Fit);
  JSBIND_ENUM_VALUE(Fill);
  JSBIND_ENUM_VALUE(Balance);
}

JSBIND_CLASS(NJSRtcClient) {
	JSBIND_CONSTRUCTOR<std::string, std::string, std::function<void()>, bool>();
	JSBIND_METHOD(Connect);
	JSBIND_METHOD(Disconnect);
	JSBIND_METHOD(SetRemoteRender);
  JSBIND_METHOD(SetLocalRender);
  JSBIND_METHOD(StartScreenCast);
  JSBIND_METHOD(StopScreenCast);
  JSBIND_METHOD(FlipCamera);
  JSBIND_METHOD(MuteMic);
  JSBIND_METHOD(UnMuteMic);
}

JSBIND_CLASS(NJSVideoRenderManager) {
  JSBIND_METHOD(GetInstance);
  JSBIND_METHOD(GetRender);
  JSBIND_METHOD(DisposeRender);
}

JSBIND_CLASS(NJSVideoRender) {
  JSBIND_METHOD(DrawYuvFile);
  JSBIND_METHOD(DrawYuvBuffer);
  JSBIND_METHOD(ClearColor);
  JSBIND_METHOD(Release);
}

JSBIND_CLASS(NJSCameraCapture) {
  JSBIND_METHOD(GetCameraDeviceId);
  JSBIND_CONSTRUCTOR<int, int, int, std::string>();
  JSBIND_METHOD(StartCapture);
  JSBIND_METHOD(StopCapture);
  JSBIND_METHOD(SetWindowOrientation);
  JSBIND_METHOD(SetSensorOrientation);
  JSBIND_METHOD(BindPreviewRender);
}
}
